package com.ruoyi.fission.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.business.domain.dto.admin.fission.FissionActivitySysAddDTO;
import com.ruoyi.business.domain.fission.TbWecomChatGroupFission;
import com.ruoyi.business.domain.vo.fission.admin.FissionActivitySysDetailVO;
import com.ruoyi.business.service.fission.ITbWecomChatGroupFissionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

@Validated
@Api(value = "企微群裂变活动管理", tags = {"企微群裂变活动管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/wecom/chat/group/fission")
public class WecomChatGroupFissionController extends BaseController {

    @Resource
    private ITbWecomChatGroupFissionService tbWecomChatGroupFissionService;

    @ApiOperation("添加企微群裂变活动")
    @SaCheckPermission("wecom:chat:group:fission:add")
    @PostMapping("/sys-add")
    public R<Boolean> sysAdd(@Validated @RequestBody FissionActivitySysAddDTO fissionActivitySysAddDTO) {
        return R.ok(tbWecomChatGroupFissionService.sysAdd(fissionActivitySysAddDTO));
    }

    // 分页查询企微群裂变活动列表
    @ApiOperation("分页查询企微群裂变活动列表")
    @SaCheckPermission("wecom:chat:group:fission:page")
    @GetMapping("/sys-page")
    public TableDataInfo<TbWecomChatGroupFission> sysPage(@ApiParam("活动名称") @RequestParam(required = false) String name,
                                                          PageQuery pageQuery) {
        return tbWecomChatGroupFissionService.sysPageQuery(name, pageQuery);
    }

    // 详情
    @ApiOperation("根据fissionId查询活动详情")
    @SaCheckPermission("wecom:chat:group:fission:detail")
    @GetMapping("sys-detail/{fissionId}")
    public R<FissionActivitySysDetailVO> getInfo(@ApiParam("群列变活动id")
                                                 @NotNull(message = "群列变活动id不能为空")
                                                 @PathVariable("fissionId") Long fissionId) {
        return R.ok(tbWecomChatGroupFissionService.sysSelectDetail(fissionId));
    }

    // 删除
    @ApiOperation("删除群裂变活动")
    @SaCheckPermission("wecom:chat:group:fission:remove")
    @DeleteMapping("sys-remove/{fissionId}")
    public R<Boolean> remove(@ApiParam("群裂变活动主键Id") @PathVariable Long fissionId) {
        return R.ok(tbWecomChatGroupFissionService.sysRemove(fissionId));
    }

    // 开始活动 生成活动入口
    @ApiOperation("开始活动并生成活动入口")
    @SaCheckPermission("wecom:chat:group:fission:start")
    @PutMapping("sys-start/{fissionId}")
    public R<Boolean> startFission(@ApiParam("群裂变活动主键Id") @PathVariable Long fissionId) {
        return R.ok(tbWecomChatGroupFissionService.sysStart(fissionId));
    }


}
